package com.lagou.homework.modulefour.third;

/*
 * @className Train
 * @description 火车票
 * @author admin
 * @date 2022/4/1 16:21
 * */
public class Train {

    private int number = 0;

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public synchronized void consumerTrainTicket(){
        if(number++<100){
            System.out.println("线程"+Thread.currentThread().getName()+"购买了第"+number+"张火车票!");
        }else{
            System.out.println("火车票已售完！");
            System.exit(0);
        }
    }
}
